package iterator.improve;

import java.util.Iterator;

/**
 * 计算机学院迭代器
 */
public class ComputerCollegeIterator implements Iterator<Department> {
    private final Department[] departments;
    private int index = 0;

    public ComputerCollegeIterator(Department[] departments) {
        this.departments = departments;
    }

    @Override
    public boolean hasNext() {
        return departments.length > 0 && departments[index] != null;
    }

    @Override
    public Department next() {
        Department department = departments[index];
        index++;
        return department;
    }
}
